package com.fg.zrcommunity.controller;

import com.fg.zrcommunity.bean.Admin;
import com.fg.zrcommunity.common.ResultInfo;
import com.fg.zrcommunity.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员的控制器
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @GetMapping("/admins")
    public ResultInfo selectAll() {
        ResultInfo r = new ResultInfo();
        try {
            List<Admin> admins = adminService.selectAll();
            r.ok(admins);
        } catch (Exception e) {
            r.error(e);
        }
        System.out.println("r = " + r);
        return r;
    };


    // 启用和禁用
    @PatchMapping("/admins/{id}")
    public ResultInfo setState(@PathVariable("id") int id) {
        ResultInfo r = new ResultInfo();

        try {
            adminService.setState(id);
            r.ok();
        } catch (Exception e) {
            r.error();
        }

        return r;
    }



}
